<?php
/**
 * bom.php 是文件头部包含了不可见字符BOM 对应的十六进制是 EF BB BF
 * 会导致api解析数据失败
 */
function check($file = null) {
    var_dump($file);
    $file = 'http://localhost/bom/' . ($file ?: 'bom.php');
    $contents = trim(file_get_contents($file));
    $chars = substr($contents, 0, 3);
    var_dump($contents, $chars, bin2hex($chars));
}

function create() {
    $hexStr = "EFBBBF";
    $str = hex2bin($hexStr);
    var_dump($str);

    $str .= '<?php
    echo "hello world";';
    file_put_contents('./newbom.php', $str);
}

if (($_GET['r'] ?? '') == 'create') {
    create();
} else {
    check($_GET['f'] ?? null);
}
